package ru.myrtle.umf.codegen;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class GenDomain<ContextType> {

    private final String name;
    private final Collection<GenArtifact<ContextType>> artifacts =
            new ArrayList<GenArtifact<ContextType>>();

    /*
     *
     */

    public GenDomain(String name, GenArtifact<ContextType>... artifacts) {
        this.name = name;
        this.artifacts.addAll(
                Arrays.asList(artifacts)
        );
    }

    /*
     *
     */

    public String getName() {
        return name;
    }

    /*
     *
     */

    public void generate(Object object, ResourceSet fileSystem, GenMonitor monitor, ContextType context)
            throws GenException {
        
        monitor.domainStarted(name);

        ResourceDomain resourceDomain =
                fileSystem.getDomain(
                        name
                );

        for (GenArtifact<ContextType> artifact : artifacts) {
            artifact.generate(
                    object, resourceDomain, monitor, context
            );
        }

        monitor.domainFinished();
    }
}
